#include "BlockQueue.hpp"

void* costomer(void* arg)
{
    BlockQueue<int>* clint = (BlockQueue<int>*)arg;
    sleep(1);
    while (1)
    {
        int a;
        clint->pop(a);
        std::cout << pthread_self() << " 消费一个：" << a << std::endl;
    }
    
}

void* producter(void* arg)
{
    BlockQueue<int>* product = (BlockQueue<int>*)arg;
    int a = 1;
    while (1)
    {
        product->push(a);
        std::cout << pthread_self() <<  " 生产一个: " << a << std:: endl;
        a++;
        sleep(1);
    }
}


int main()
{
    // 先完成单对单的 生产者，消费者
    pthread_t a[2], b[2];
    BlockQueue<int> BQ;
    pthread_create(a, nullptr, costomer, (void*)&BQ);
    pthread_create(a + 1, nullptr, costomer, (void*)&BQ);
    pthread_create(b, nullptr, producter, (void*)&BQ);
    pthread_create(b + 1, nullptr, producter, (void*)&BQ);

    pthread_join(a[0], nullptr);
    pthread_join(a[1], nullptr);
    pthread_join(b[0], nullptr);
    pthread_join(b[1], nullptr);

    return 0;
}


